package com.neihe.controller;

import com.neihe.entity.dto.share.CancelShareDTO;
import com.neihe.entity.dto.share.CheckShareCodeDTO;
import com.neihe.entity.dto.share.CreateShareUrlDTO;
import com.neihe.entity.vo.share.ShareDetailVO;
import com.neihe.entity.vo.share.ShareSimpleDetailVO;
import com.neihe.entity.vo.share.ShareUrlListVO;
import com.neihe.entity.vo.share.ShareUrlVO;
import com.neihe.service.IShareService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 分享模块
 *
 * @author neihe
 * @since 2025-02-06
 */
@RestController
public class ShareController {

    @Autowired
    private IShareService shareService;

    /**
     * 创建分享链接
     *
     * @param requestParam 请求参数
     * @return 分享详情
     */
    @PostMapping("/api/share/private/create")
    public ShareUrlVO create(@Valid @RequestBody CreateShareUrlDTO requestParam) {
        return shareService.create(requestParam);
    }

    /**
     * 查询分享链接列表
     *
     * @return 结果
     */
    @GetMapping("/api/share/private/list")
    public List<ShareUrlListVO> getShares() {
        return shareService.getShares();
    }

    /**
     * 取消分享
     *
     * @param requestParam 请求参数
     */
    @PostMapping("/api/share/private/cancel")
    public void cancelShare(@Valid @RequestBody CancelShareDTO requestParam) {
        shareService.cancelShare(requestParam);
    }

    /**
     * 查询分享的简单详情
     *
     * @param identifier 分享唯一标识
     * @return 结果
     */
    @GetMapping("/api/share/public/simple")
    public ShareSimpleDetailVO simpleDetail(@RequestParam String identifier) {
        return shareService.simpleDetail(identifier);
    }

    /**
     * 校验提取码
     *
     * @param requestParam 请求参数
     * @return 结果
     */
    @PostMapping("/api/share/public/code/check")
    public String checkShareCode(@Valid @RequestBody CheckShareCodeDTO requestParam) {
        return shareService.checkShareCode(requestParam);
    }

    /**
     * 查询分享的详情
     */
    @GetMapping("/api/share/private/detail")
    public ShareDetailVO detail(String token) {
        return shareService.detail(token);
    }
}
